home *** CD-ROM | disk | FTP | other *** search
- Path: news.th-darmstadt.de!news!enno
- From: enno@inferenzsysteme.informatik.th-darmstadt.de (Enno Sandner)
- Newsgroups: comp.lang.c++
- Subject: Re: Why use private class members instead of protected?
- Date: 14 Jan 1996 16:30:34 GMT
- Organization: Fachbereich Informatik, TH Darmstadt
- Distribution: world
- Message-ID: <ENNO.96Jan14173035@kitz.inferenzsysteme.informatik.th-darmstadt.de>
- References: <30F4AB49.6ABB@sierra.net>
- <30F50874.15FB7483@intellektik.informatik.th-darmstadt.de>
- <4d3q07$n8o@geraldo.cc.utexas.edu>
- <30F61CAC.2781E494@intellektik.informatik.th-darmstadt.de>
- <WIKMAN.96Jan14100533@falcon.research.nokia.com>
- NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
- In-reply-to: wikman@falcon.research.nokia.com's message of 14 Jan 1996 08:05:33 GMT
-
- In article <WIKMAN.96Jan14100533@falcon.research.nokia.com> wikman@falcon.research.nokia.com (Johan Wikman) writes:
-
- In article <30F61CAC.2781E494@intellektik.informatik.th-darmstadt.de> Enno Sandner <enno@intellektik.informatik.th-darmstadt.de> writes:
-
- However an accessor/mutator pair like
-
- void MyClass :: set_data(const DataType&) { ... }
- DataType MyClass :: get_data() const { return _data; }
-
- completely avoids this sort of problems. If the 'DataType' uses some
- technique to speed up copying (for example ref-counting) the overhead
- is minimal.
-
- I think you only change the problem into something else. Now if you
- ever choose to change the representation of '_data' you face the
- problem of converting a DataType to and from whatever type '_data'
- is. The problem is still there, it has only changed shape.
-
- Nevertheless it adds some sort of 'stability' to the class, because
- necessary conversions can performed without changing the interface.
- So, _if_ you need to access data-members of the base-classe(s) it's
- _often_ a better choice to use accessor/mutator pairs compared to
- making all data-members protected.
-
- In my opinion it fairly seldom makes sense to provide accessor/mutator
- functions to the data members of a class. In fact, I get suspicious
- when a class reminds you of a data repository instead of reminding you
- of something that provides behaviour.
-
- Agreed.
-
- Enno
-